

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="public/css/style.css" />
        <?php
        //Require your file here
        require_once 'template/Pagination.php';
        require_once 'model/works.php';

        $md_works = new Works();
        $pagination = new Pagination();
        
        $works = $md_works ->select();
        $total = count($works);
        $page = 1 ; 
        if (isset($_GET['page'])){
            $page = $_GET['page'];
        }
        $works = $md_works ->select(NULL,$page);
        $paginations = $pagination ->display($page, $total);
        ?>

    </head>
    <body>
        <div class="container">
           <?php include './template/header.php'; ?>
            <?php
            if (isset($_SESSION["flag"])) {
                include "display-login.php";
                ?>
                
                <?php
            } else
                include "login.php";
            ?>
            <br>
<a href="logout.php">logout</a>
            <div class="content">
                <?php echo $paginations; ?>
                <table >
                    <tr>
                        <td>Id</td>
                        <td>Name</td>
                         <td>Description</td>
                        <td>Image</td>
                        <td>Edit</td>

                    </tr>
                    <?php foreach ($works as $work): ?>
                        <tr>
                            <td><?php echo $work['id'] ?></td>
                            <td><?php echo $work['name'] ?></td>
                            <td><?php echo substr($work['description'], 0, 1000) ?></td>
                            <td><img style="width: 150px; height: 150px;" src='<?php echo $work['image'] ?>'/></td>

                            <?php if (!empty($_SESSION['flag'])): ?>
                                <td><a href='edit.php?id=<?php echo $work['id'] ?>'>edit</a></td>

                                <td><a href='delete.php?id=<?php echo $work['id'] ?>'>delete</a></td>

                            <?php endif; ?>
                            <td><a href='view.php?id=<?php echo $work['id'] ?>'/>view</a></td>

                        </tr>
                    <?php endforeach; ?>
                </table>
            </div>
            <!-- Include footer-->
            <?php include ('template/footer.php') ?>
        </div>
    </body>
</html>